package com.xinchao.controller;

import com.xinchao.model.page.PageInfo;
import com.xinchao.model.vo.OperationLogListVO;
import com.xinchao.service.OperationLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping(value = "/operationLog")
public class OperationLogController {
	private static Logger logger = LoggerFactory.getLogger(OperationLogController.class);

	@Autowired
	private OperationLogService operationLogService;

	/**
	 * 操作日志列表
	 */
	@RequestMapping(value = "/list")
	public String listOperationLog(String startTime, String endTime, Integer pageNum, Integer pageSize, Model model, HttpServletRequest request) {
		try {
			PageInfo<OperationLogListVO> operationLogPageInfo = operationLogService.listOperationLogByPage(startTime, endTime, pageNum, pageSize);
			model.addAttribute("startTime", startTime);
			model.addAttribute("endTime", endTime);
			model.addAttribute("operationLogList", operationLogPageInfo.getList());
			model.addAttribute("pageNum", operationLogPageInfo.getPageNum());
			model.addAttribute("pageSize", operationLogPageInfo.getPageSize());
			model.addAttribute("total", operationLogPageInfo.getTotal());
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("OperationLogController listOperationLog 获取操作日志列表失败：" + e.getMessage());
		}
		return "operationLog_list";
	}
}
